<template>
  <div class="form-container">
    <div class="form-wrapper">
      <div class="form-title">意见反馈</div>
      <el-form ref="form" label-position="top" :model="form" :rules="rules">
        <el-form-item label="联系方式" prop="phone_number">
          <el-input placeholder="请输入联系方式" v-model="form.phone_number"></el-input>
        </el-form-item>
        <el-form-item label="意见反馈" prop="content">
          <el-input placeholder="请输入意见反馈" v-model="form.content" type="textarea" :autosize="{ minRows: 5, maxRows: 10}"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="width: 100%;" @click="submitForm">提&nbsp;&nbsp;&nbsp;&nbsp;交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { addFeedback } from '@/api/feedback'

export default {
  name: 'Feedback',
  data() {
    return {
      form: null,
      rules: {
        phone_number: [
          { required: true, message: '请输入联系方式', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入意见反馈', trigger: 'blur' }
        ],
      }
    }
  },
  created() {
    this.resetForm()
  },
  methods: {
    resetForm() {
      this.form = {
        phone_number: null,
        content: null
      }
    },
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          addFeedback(this.form).then(res => {
            console.log(res)
            if (res.code === 200) {
              this.$message({
                message: "提交成功，感谢您的反馈，我们将尽快与您联系。",
                type: 'success',
                duration: 1000
              })
              this.resetForm()
            } else {
              this.$message({
                message: res.msg,
                type: 'error',
                duration: 1000
              })
            }
          })
        }
      })
    },
  },
}
</script>
<style>
.form-wrapper {
  width: 600px;
  margin: 120px auto;
  padding: 50px;
  border: 1px solid #C0C4CC;
  border-radius: 5px;
  background: #ffffff;
  opacity: 0.8;
}
.form-container {
  padding: 1px; 
  background-size: cover;
}
.form-title {
  width: 100%;
  margin-bottom: 22px;
  font-size: 30px;
  text-align: center;
}
</style>
